package models;

import java.io.Serializable;
import javax.persistence.*;

import service.ActorService;

import java.util.Date;

/**
 * The persistent class for the account database table.
 * 
 */
@Entity
@Table(name = "ACCOUNT")
public class Account implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @TableGenerator(
            name = "ACCOUNT_SEQ",
            table = "SEQUENCE",
            pkColumnName = "NAME",
            pkColumnValue = "ACCOUNT_SEQ",
            valueColumnName = "CNT",
            initialValue = 10000,
            allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "ACCOUNT_SEQ")
    @Column(unique = true, nullable = false)
    private Integer id;

    @Column(name = "ACCOUNT_INSTITUTION", length = 100)
    private String accountInstitution;

    @Column(name = "ACCOUNT_NAME", length = 100)
    private String accountName;

    @Column(name = "ACCOUNT_NUM", length = 100)
    private String accountNum;

    private Integer aid;

    @Column(length = 150)
    private String branch;

    @Column(length = 50)
    private String city;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "CREATE_D")
    private Date createD;

    @Column(length = 50)
    private String province;

    private int type;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "UPDATE_D")
    private Date updateD;

    public Account() {
    }

    public void setValues(Integer aid, String name, Account.ChineseProvince province, String city,
            Account.FinancialInstitution institution, String accountNumber) {
        this.setAid(aid);
        this.setAccountInstitution(institution);
        this.setAccountName(name);
        this.setCity(city);
        this.setProvince(province);
        this.setType(Account.Type.SAVING);
        this.setCreateD(new Date());
        this.setUpdateD(new Date());
        this.setAccountNum(accountNumber);
    }

    public String getAccountInstitution() {
        return this.accountInstitution;
    }

    public void setAccountInstitution(FinancialInstitution accountInstitution) {
        this.accountInstitution = accountInstitution.getChineseName();
    }

    public String getAccountName() {
        return this.accountName;
    }

    public void setAccountName(String accountName) {
        this.accountName = accountName;
    }

    public String getAccountNum() {
        return this.accountNum;
    }

    public void setAccountNum(String accountNum) {
        this.accountNum = accountNum;
    }

    public String getBranch() {
        return this.branch;
    }

    public void setBranch(String branch) {
        this.branch = branch;
    }

    public String getCity() {
        return this.city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public Date getCreateD() {
        return this.createD;
    }

    public void setCreateD(Date createD) {
        this.createD = createD;
    }

    public String getProvince() {
        return this.province;
    }

    public void setProvince(ChineseProvince province) {
        this.province = province.chineseName;
    }

    public Type getType() {
        Type[] vals = Type.values();
        if (this.type > vals.length - 1 || this.type < 0)
            return null;
        return Type.values()[this.type];
    }

    public void setType(Type type) {
        this.type = type.ordinal();
    }

    public Date getUpdateD() {
        return this.updateD;
    }

    public void setUpdateD(Date updateD) {
        this.updateD = updateD;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public void setAid(Integer aid) {
        this.aid = aid;
    }

    public Integer getId() {
        return id;
    }

    public Integer getAid() {
        return aid;
    }

    public enum FinancialInstitution {
        ICBC("Industrial and Commercial Bank of China", "中国工商银行"),
        ABC("Agricultural Bank of China", "中国农业银行"),
        BOC("Bank of China", "中国银行"),
        CCB("China Construction Bank", "中国建设银行"),
        BC("Bank of Communications", "交通银行"),
        CB("CITIC Bank", "中信银行"),
        CEB("China Everbright Bank", "中国光大银行"),
        HB("Huaxia Bank", "华夏银行"),
        CMB("China Minsheng Bank", "中国民生银行"),
        GDB("Guangdong Development Bank", "广东发展银行"),
        SDB("Shenzhen Development Bank", "深圳发展银行"),
        MB("Merchants Bank", "招商银行"),
        IB("Industrial Bank", "兴业银行"),
        SPDB("Shanghai Pudong Development Bank", "上海浦东发展银行"),
        BOB("Bank of Beijing", "北京银行"),
        BOS("Bank of Shanghai", "上海银行"),
        CCMB("City commercial banks", "城市商业银行"),
        RCC("Rural Credit Cooperatives", "农村信用合作社"),
        SB("Shengjing Bank", "盛京银行"),
        BOT("Bank of Tianjin", "天津银行"),
        BON("Bank of Ningbo", "宁波银行"),
        CHB("Chongqing Bank", "重庆银行"),
        BOW("Bank of Wenzhou", "温州银行"),
        BONA("Bank of Nanjing", "南京银行"),
        BOJ("Bank of Jiangsu", "江苏银行"),
        SPB("Shenzhen Ping An Bank", "深圳平安银行"), ;
        private String name;

        private String chineseName;

        FinancialInstitution(String name, String chineseName) {
            this.name = name;
            this.chineseName = chineseName;
        }

        public String getName() {
            return this.name;
        }

        public String getChineseName() {
            return this.chineseName;
        }

        public static FinancialInstitution getByChineseName(String chineseName) {
            for (FinancialInstitution institution : FinancialInstitution.values()) {
                if (chineseName != null && chineseName.equals(institution.getChineseName())) {
                    return institution;
                }
            }
            return null;
        }

    }

    public static enum ChineseProvince {
        Beijing("Beijing", "北京", new String[] { "北京" }),
        Tianjin("Tianjin", "天津", new String[] { "天津" }),
        Hebei("Hebei", "河北", new String[] { "石家庄", "保定", "沧州", "承德", "邯郸", "衡水", "廊坊", "秦皇岛", "唐山", "邢台", "张家口" }),
        Shanxi("Shanxi", "山西", new String[] { "太原", "长治", "大同", "晋城", "离石", "临汾", "朔州", "忻州", "阳泉", "榆次", "运城", "晋中",
                "吕梁" }),
        InnerMongolia("Inner Mongolia", "内蒙古", new String[] { "呼和浩特", "包头", "阿拉善", "巴彦淖尔", "赤峰", "呼伦贝尔", "乌海", "乌兰察布",
                "锡林郭勒", "兴安", "鄂尔多斯", "通辽" }),
        Liaoning("Liaoning", "辽宁", new String[] { "沈阳", "大连", "鞍山", "本溪", "朝阳", "丹东", "抚顺", "阜新", "葫芦岛", "锦州", "辽阳",
                "盘锦", "铁岭", "营口" }),
        Jilin("Jilin", "吉林", new String[] { "长春", "白城", "白山", "吉林", "辽源", "四平", "松原", "通化", "延边" }),
        Heilongjiang("Heilongjiang", "黑龙江", new String[] { "哈尔滨", "大庆", "大兴安岭", "鹤岗", "黑河", "鸡西", "佳木斯", "牡丹江", "七台河",
                "齐齐哈尔", "双鸭山", "绥化", "伊春" }),
        Shanghai("Shanghai", "上海", new String[] { "上海" }),
        Jiangsu("Jiangsu", "江苏", new String[] { "南京", "常州", "淮安", "连云港", "南通", "苏州", "宿迁", "泰州", "无锡", "徐州", "盐城",
                "扬州", "镇江", "胥浦", "昆山" }),
        Zhejiang("Zhejiang", "浙江", new String[] { "杭州", "宁波", "湖州", "嘉兴", "金华", "绍兴", "台州", "温州", "舟山", "衢州", "丽水" }),
        Anhui("Anhui", "安徽", new String[] { "合肥", "安庆", "蚌埠", "巢湖", "池州", "滁州", "阜阳", "淮北", "淮南", "黄山", "六安", "马鞍山",
                "铜陵", "芜湖", "宣城", "亳州", "宿州" }),
        Fujian("Fujian", "福建", new String[] { "福州", "厦门", "龙岩", "南平", "宁德", "莆田", "泉州", "三明", "漳州" }),
        Jiangxi("Jiangxi", "江西", new String[] { "南昌", "抚州", "赣州", "吉安", "景德镇", "九江", "萍乡", "上饶", "新余", "宜春", "鹰潭" }),
        Shandong("Shandong", "山东", new String[] { "济南", "青岛", "滨州", "德州", "东营", "菏泽", "济宁", "莱芜", "聊城", "临沂", "日照",
                "泰安", "威海", "潍坊", "烟台", "枣庄", "淄博" }),
        Henan("Henan", "河南", new String[] { "郑州", "安阳", "焦作", "鹤壁", "开封", "洛阳", "南阳", "平顶山", "三门峡", "商丘", "新乡", "信阳",
                "许昌", "周口", "驻马店", "漯河", "濮阳", "济源" }),
        Hubei("Hubei", "湖北", new String[] { "武汉", "鄂州", "恩施", "黄冈", "黄石", "荆门", "荆州", "十堰", "随州", "咸宁", "襄樊", "孝感",
                "神农架", "天门", "宜昌", "三峡" }),
        Hunan("Hunan", "湖南", new String[] { "长沙", "常德", "郴州", "衡阳", "怀化", "娄底", "邵阳", "湘潭", "湘西", "益阳", "永州", "岳阳",
                "张家界", "株洲" }),
        Guangdong("Guangdong", "广东", new String[] { "广州", "深圳", "潮州", "东莞", "佛山", "惠州", "江门", "揭阳", "茂名", "梅州", "清远",
                "汕头", "汕尾", "韶关", "阳江", "云浮", "湛江", "肇庆", "中山", "河源", "珠海" }),
        Guangxi("Guangxi", "广西", new String[] { "南宁", "百色", "北海", "桂林", "河池", "柳州", "梧州", "玉林", "崇左", "防城港", "贵港",
                "贺州", "来宾", "钦州" }),
        Hainan("Hainan", "海南", new String[] { "海口", "三亚", "白沙", "保亭", "昌江", "澄迈", "儋州", "定安", "东方", "乐东", "临高", "陵水",
                "琼海", "琼中", "屯昌", "万宁", "文昌", "五指山", "洋浦" }),
        Chongqing("Chongqing", "重庆", new String[] { "重庆" }),
        Sichuan("Sichuan", "四川", new String[] { "成都", "巴中", "达州", "德阳", "广安", "广元", "乐山", "凉山", "眉山", "绵阳", "南充", "内江",
                "攀枝花", "遂宁", "雅安", "宜宾", "自贡", "泸州", "阿坝", "甘孜", "资阳" }),
        Guizhou("Guizhou", "贵州", new String[] { "贵阳", "安顺", "毕节", "六盘水", "铜仁", "遵义", "黔东南", "黔南", "黔西南" }),
        Yunnan("Yunnan", "云南", new String[] { "昆明", "西双版纳", "保山", "楚雄", "大理", "德宏", "红河", "丽江", "临沧", "怒江", "曲靖", "思茅",
                "文山", "玉溪", "昭通", "中甸", "迪庆州" }),
        Tibet("Tibet", "西藏", new String[] { "拉萨", "阿里", "昌都", "林芝", "那曲", "日喀则", "山南" }),
        Shanxi2("Shanxi Province", "陕西", new String[] { "西安", "安康", "宝鸡", "汉中", "商洛", "铜川", "渭南", "咸阳", "延安", "榆林" }),
        Gansu("Gansu", "甘肃", new String[] { "兰州", "白银", "定西", "东风", "合作", "嘉峪关", "金昌", "酒泉", "矿区", "临夏", "陇南", "平凉",
                "庆阳", "天水", "武威", "张掖", "甘南州" }),
        Qinghai("Qinghai", "青海", new String[] { "西宁", "海东" }),
        Ningxia("Ningxia", "宁夏", new String[] { "银川", "中卫", "固原", "石嘴山", "吴忠" }),
        Xinjiang("Xinjiang", "新疆", new String[] { "乌鲁木齐", "阿克苏", "阿勒泰", "巴州", "博州", "昌吉", "哈密", "和田", "喀什", "克拉玛依",
                "马兰", "石河子", "塔城", "吐鲁番", "伊犁", "克州", "阿拉尔", "五家渠" }),

        ;

        private String name;

        private String chineseName;

        private String[] cities;

        ChineseProvince(String name, String chineseName, String[] cities) {
            this.name = name;
            this.chineseName = chineseName;
            this.cities = cities;
        }

        public String getName() {
            return name;
        }

        public String getChineseName() {
            return chineseName;
        }

        public String[] getCities() {
            return cities;
        }

        public static ChineseProvince getProvinceByChineseName(String chineseName) {
            for (ChineseProvince province : ChineseProvince.values()) {
                if (chineseName != null && chineseName.equals(province.getChineseName())) {
                    return province;
                }
            }
            return null;
        }

        public boolean hasCity(String chineseName) {
            for (String city : cities) {
                if (chineseName != null && chineseName.equals(city)) {
                    return true;
                }
            }
            return false;
        }
    }

    public enum Type {
        ANY, // 0
        SAVING, // 1
        CREDIT// 2
    }
}